export default {
  install (Vue) {
    Vue.filter("unit", function (price) {
      var arr = price + ''
      arr = arr.split('.');
      if (arr.length == 2) {
        let zhengshu = arr[0];  //获取整数部分
        let xiaoshu = arr[1];   //获取小数部分
        var num
        if (xiaoshu.length == 2) {
          let value = (zhengshu + xiaoshu) * 100;
          num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        } else if (xiaoshu.length == 3) {
          let value = (zhengshu + xiaoshu) * 10;
          num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        } else if (xiaoshu.length == 4) {
          let value = (zhengshu + xiaoshu) * 1;
          num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        }

        else {
          let value = (zhengshu + xiaoshu) * 1000;
          num = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        }
        return num
      } else {
        return (price * 10000).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
      }
    })
    Vue.filter("two",function (data){
      return data < 10 ? '0' + data : data
    })
  }
}
